package cn.volunteer.points.system.controller;

import cn.volunteer.points.system.system_enum.RespResult;

import java.util.Date;

/**
 * @description: API接口父类
 * @author:
 * @create: 创建时间：2021-04-16
 **/
public class RestfulController {

    //请求处理成功，返回业务数据
    <T> Response<T> success(T data) {
        Response<T> respResult = new Response();
        respResult.setResponseTime(new Date());
        respResult.setCode(0);
        respResult.setData(data);
        return respResult;
    }

    //请求处理成功，返回业务数据
    <T> Response<T> success(T data , String msg) {
        Response<T> respResult = new Response();
        respResult.setResponseTime(new Date());
        respResult.setCode(0);
        respResult.setData(data);
        respResult.setMsg(msg);
        return respResult;
    }

    //请求处理失败，返回提示信息
    <T> Response<T> fail() {
        Response<T> respResult = new Response();
        respResult.setResponseTime(new Date());
        respResult.setCode(503);
        return respResult;
    }

    //请求处理失败，返回提示信息
    <T> Response<T> fail(String msg) {
        Response<T> respResult = new Response();
        respResult.setResponseTime(new Date());
        respResult.setCode(503);
        respResult.setMsg(msg);
        return respResult;
    }
}
